package com.kakame.codenews.base.web.websocket.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import com.kakame.codenews.base.web.interceptor.WebSocketInterceptor;
import com.kakame.codenews.base.web.websocket.handler.SiteInnerMessageHandler;

@Configuration
@EnableWebSocket
@EnableWebMvc
public class WebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketConfigurer {
 
	/**
	 * 提供配置自己的websocekt类即请求路径
	 */
	@Override
	public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
		registry.addHandler(siteInnerMessageHandler(),"/websocket/siteInnerMessage.html")
				.addInterceptors(new WebSocketInterceptor());
	}
 
	/**
	 * 向spring容器注册javabean由spring容器来管理
	 * @return
	 */
	@Bean
	public WebSocketHandler siteInnerMessageHandler(){
		return new SiteInnerMessageHandler();
	}
}